$(function () {
    loading();
    ajaxMyScore(1);
});
/**
 * 加载我的专项积分
 * @param page    当前页码
 */
function ajaxMyScore(page) {
    var url = "/Lvscore_User_M/adScore/ajaxMyScore";
    $.post(
        url,
        {'page': page},
        function (data) {
            /*map：
             sumpage：总页数
             nowpage：页码
             userTowardBalanceDtoList：
             List<UserTowardBalanceDto>  我的专项积分列表
             userTowardBalance：UserTowardBalanceBean
             developer：DeveloperBean*/
            $("#info").empty();
            if(data.userTowardBalanceDtoList.length==0){
                $("#info").css("border","none").append('<p class="noResult"><img src="/Lvscore_User_M/userWeb/static/images/dissearch.png" alt="">暂时没有专项积分</p>')
            }else{
                $("#info").append(
                    "<tr>" +
                    "<th>序号</th>" +
                    "<th>名称</th>" +
                    "<th>已获的广告收入(元)</th>" +
                    "<th>已支付(元)</th>" +
                    "<th>余额(元)</th>" +
                    "</tr>"
                );
                $.each(data.userTowardBalanceDtoList, function (i, e) {
                    if (isNotEmpty(e.application)) {
                        $("#info").append(
                            "<tr>" +
                            "<td>" + (i + 1) + "</td>" +    // /Lvscore_User_M/userWeb/views/ADadmin/accounterMoney/productList.html?id=" + e.application.id + "
                            "<td><a href='javascript:;' title=''>" + e.application.name + "</a></td>" +
                            "<td>" + e.userTowardBalance.totalBalance + "</td>" +
                            "<td class='red'> -" + (e.userTowardBalance.totalBalance - e.userTowardBalance.balance).toFixed(2) + "</td>" +
                            "<td class='green'>" + (e.userTowardBalance.balance - 0).toFixed(2) + "</td>" +
                            "</tr>"
                        );
                    } else {
                        $("#info").empty();
                        $("#info").css("border", "none").html('<p class="noResult"><img src="/Lvscore_User_M/userWeb/static/images/dissearch.png" alt="">未查询到任何数据</p>');
                    }
                });
            }
            if ($(".tcdPageCode").html() == "") {
                createPage(data.sumpage, data.nowpage);
            }
            $(".loadingBox").hide();
        },
        "json");
}

/**
 * 我的专项积分余额分页
 * @param pages当前页数
 * @param pageNum总页数
 * @returns
 */
function createPage(pages, pageNum) {
    if (pages > 1) {
        $(".tcdPageCode").createPage({
            pageCount: pages,
            current: pageNum,
            backFn: function (p) {
                ajaxMyScore(p);
            }
        });
    }
}